# coding:utf-8
import requests
from bs4 import BeautifulSoup
import time
import re
import csv
import chardet
for i in range(0,10):
    link = 'https://movie.douban.com/top250?start=' + str(i * 25)
    r = requests.get(link)
    print(r.status_code)
    soup = BeautifulSoup(r.text,'lxml')
    div_list = soup.find_all('div', class_='hd')
    for list in div_list:
        movie = list.a
        movie_name = list.a.span.text.strip()
        print(chardet.detect(movie_name))
        link = re.findall('http.*\/',str(movie))
        print(link)
        with open('douban', 'a+') as fp:
            fp.write(movie_name)
        time.sleep(1)
